package com.imy.lua.dialog;

import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.imy.common.base.BaseDialog;
import com.imy.common.base.BaseKeyboardDialog;
import com.imy.common.util.ToastUtil;
import com.imy.lua.R;


public class ColorFindDialogTips extends BaseKeyboardDialog {
    private EditText colorFindEt;
    private TextView manualTv;
    private TextView confirmTv;
    private EditText dimEt;

    public ColorFindDialogTips(AppCompatActivity activity) {
        super(activity);
    }

    @Override
    protected void init(View view) {
        super.init(view);
        getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

        colorFindEt = view.findViewById(R.id.color_find_et);
        dimEt = view.findViewById(R.id.color_dim_et);
        manualTv = view.findViewById(R.id.manual_tv);
        confirmTv = view.findViewById(R.id.confirm_tv);
        manualTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s1 = dimEt.getText().toString();
                float v1 = Float.parseFloat(s1);
                if (v1 > 1.0f) {
                    ToastUtil.toast(mActivity, R.string.input_right_dim_value);
                    return;
                }
                dismiss();
                listener.onFindColor("", v1);
            }
        });
        confirmTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                //判断下结果
                String s = colorFindEt.getText().toString();
                if (TextUtils.isEmpty(s)
                        || !s.contains("#")
                        || s.length() != 7) {
                    ToastUtil.toast(mActivity, R.string.input_right_color_value);
                    return;
                }
                try {
                    String s1 = dimEt.getText().toString();
                    float v1 = Float.parseFloat(s1);
                    if (v1 > 1.0f) {
                        ToastUtil.toast(mActivity, R.string.input_right_dim_value);
                        return;
                    }
                    listener.onFindColor(s,v1);
                } catch (Exception e) {
                    ToastUtil.toast(mActivity, R.string.input_right_dim_value);
                }



            }
        });

    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_color_find_in_region;
    }

    public interface InputColorListener {
        void onFindColor(String color, float v1);

    }

    public void setInputColorListener(InputColorListener listener) {
        this.listener = listener;
    }

    private InputColorListener listener;
}
